package com.example.javapoint.sync;

/**
 * 使用匿名内部类来创建线程
 */

class AnnoTable {
    public synchronized void print(int n, String name){
        for (int i = 1; i < 1000; i++) {
            System.out.println(name+ "------->" + i  * n);
            try {
                Thread.sleep(400);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

public class AnonymousClass {
    public static void main(String[] args) {
        AnnoTable table = new AnnoTable();
        Thread thread1 = new Thread(() -> {
            table.print(5, Thread.currentThread().getName());
        });

        Thread thread2 = new Thread(() -> {
            table.print(100, Thread.currentThread().getName());
        });

        thread1.start();
        thread2.start();
    }
}
